"""
3.选班长：
	step1：初始化候选人的信息：

		[Rose，Jack，王二狗，李小花，三胖]

	step2：投票：(控制台输入)
		[]
		Rose
		Jack
		Rose
		Jack
		Rose
		Rose
		Rose1-->无效
		如花-->无效
		弃权-->无效
		[Rose,Jack,Rose,Jack,Rose,Rose]
	step3：公布结果
		Rose当先班长，鼓掌，撒花。。
附加：
	Rose，Jack票数相同。？
"""
from collections import deque

lis1 = []
lis2 = [x for x in range(1, 6)]
lis_name = ["Rose", "Jack", "孙二狗", "李小花", "三胖"]
# dic_score={}
lis_score = []


def toupiao():
    i = 0
    while i < 20:
        print("请给下面这些同学投票")
        print("1.Rose", "2.Jack", "3.孙二狗", "4.李小花", "5.三胖")
        nam = input("请投票1-5：")
        if int(nam) in lis2:
            lis1.append(int(nam))
            i += 1
            if i == 20:
                break
        else:
            print("------请不要投错")


def print_count():
    print("lis3", lis3)
    for i in range(1, 6):
        s = lis3.count(i)
        lis_score.append(s)
        print("学生:%s票数:%s 票" % (lis_name[i - 1], s))


def find_hi(a, b):  # 寻找相同元素下标 a为list  b是要查找的元素
    lis_index = []
    s_index = 0
    while s_index < len(a):
        try:
            temp = a.index(b, s_index, len(a))  # 寻找0-5之间
            lis_index.append(temp)
            s_index = temp + 1  # 找到后后移一位
        except Exception:
            break

    return lis_index


def the_fisrt():
    s = max(lis_score)  # 取最大值
    bi = lis_score.index(s)  # 找最大值下标
    # print(lis_score)
    m = find_hi(lis_score, s)
    # print("最高分下标列表",m)
    if len(m) > 1:
        for j in m:
            print("%s获得%s票" % (lis_name[j], s))
        print("由于同时有同学获得最高票数，请重新投票")
    else:
        print("恭喜%s,得了%s票当选班长" % (lis_name[bi], s))


flag = True
while flag:
    toupiao()
    lis3 = deque(lis1)
    print_count()
    the_fisrt()
    break
